<?php

class shenqiModule extends Module {
	/*
	 * 在构造函数中装载所依赖的类或其他文件
	*/
	function __construct() {
		$this->includePhp('shenqi', 'shenqi');
	}
	
	
	/*
	 * 调用插件资源
	*/
	public function call($user, $method, $param) {
		//检查用户
		$customerId = Session::$user['customerId'];
		Session::switchCustomer(0);
		$uid = Session::$user['uid'];
		$quanUserModel=M("quan_user");
		Session::switchCustomer($customerId);
		$fromGuid=$param->fromGuid;
		$allowMethod="pageStart|index|getSend";
		$pos=strpos($allowMethod,$method);
		if($pos && $method!="saveAccountFree"){ 
			if(!$uid){
				Output::instance()->resultCode(1,"无权限访问");
				return;
			}
			$user=$quanUserModel->where("uid=$uid")->select();
			if(!$user || count($user) < 1){
				Output::instance()->resultCode(1,"无权限访问");
				return;
			}
		}

		switch ($method) {
			case "index":
			    $qId = $param->qId;
				shenqi::getIndex($param);
			    break;
			case "getAccoutList":
				$qId = $param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
			    shenqi::getAccoutList($param);
			    break;
			case "saveShare":
				$qId = $param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
			    shenqi::saveShare($param);
			    break;
			case "createRechangeOrder":
				$qId = $param->qId;
				if (!isset($qId)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
			    shenqi::createRechangeOrder($param);
			    break;
			case "saveAccountFree":
				if(!isset($param->id)){
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
			    shenqi::saveAccountFree($param->id);
			    break;
			case "getView":
				if(!isset($param->qId)){
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				if(!isset($param->id)){
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
			    shenqi::getView($param);
			    break;
			case "getRed":
				if(!isset($param->id)){
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
			    shenqi::getRed($param);
			    break;
			case "getRedUserList":
				if(!isset($param->id)){
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
			    shenqi::getRedUserList($param);
			    break;
			case "getSend":
				if(!isset($param->qId)){
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
			    shenqi::getSend($param);
			    break;
			case "deleteShare":
				if(!isset($param->id)){
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
			    shenqi::deleteShare($param);
			    break;

			case "rollbackAccount":
				if(!isset($param->id)){
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
			    shenqi::rollbackAccount($param);
			    break;
			case "getObjectDetail":
			 	$id=$param->id;			        
			    if (!isset($id)) {			            
			         Output::instance()->resultCode(code_lackof_param);
			         return;
			    }			        
			    return shenqi::getObjectDetail($param);
			    break;
		}
	}
}


$module = new shenqiModule();
Module::addModule($module);
?>